package com.example.sxproject.service.impl;

import com.example.sxproject.mapper.CardMapper;
import com.example.sxproject.pojo.Card;
import com.example.sxproject.pojo.Company;
import com.example.sxproject.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardServiceImpl implements CardService {
    @Autowired
    private CardMapper cardMapper;

    public List<Card> getCardsByUserId(Integer userId) {
        return cardMapper.findByUserId(userId);
    }

    //添加insert：添加一个卡
    @Override
    public void addCard(Card card) {
        cardMapper.addCard(card);
    }

    //更新：更新全部
    @Override
    public void updateAll(Card card) {
        cardMapper.updateALL(card);

    }

    //查询：验证银行卡密码
    @Override
    public boolean verifyPassword(String idNumber, String enterpassword) {
        Card card=cardMapper.findByIdNumber(idNumber);
        if(card!=null){
            //获取银行卡密码
            String cardPassword = card.getPassword();
            if(cardPassword.equals(enterpassword)){
                return true;
            }
        }
        return false;
    }

    //更新：更改指定银行卡的密码
    @Override
    public void updatePassword(String idNumber, String password) {
        cardMapper.updatePassword(idNumber, password);
    }

    //更新：更改指定银行卡的余额,
    @Override
    public void updateBalance(String idNumber, double balance) {
        cardMapper.updateBalance(idNumber, balance);
    }

    //更新：实现银行卡假删除
    @Override
    public void deleteCard(String idNumber, Integer statusId) {
        cardMapper.deleteCard(idNumber,statusId);
    }

    //根据卡号修改所属用户
    @Override
    public void updatestatusId(String idNumber,Integer userId) {
        cardMapper.updateStatusId(idNumber,userId);
    }

    //查询：根据银行卡号查询数据
    @Override
    public Card findByIdNumber(String idNumber) {
        return cardMapper.findByIdNumber(idNumber);
    }

    @Override
    public List<Card> findByStatusId() {
        return cardMapper.findByStatusId();
    }

    @Override
    public List<Card> selectByTI(Card card) {
        List<Card> cards=cardMapper.selectByTI(card);
        return cards;
    }

    @Override
    public void kaihu(Card card){
        cardMapper.kaihu(card);
    }

    @Override
    public void bohui(Integer id){
        cardMapper.bohui(id);
    }

}
